<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class penerimaan_kas extends My_Controller
{
	
	function __construct()
	{
		parent::__construct();
				$this->load->model('mdl_penerimaan_kas', 'penerimaan_kas');		$this->load->library(array('fungsi','pquery'));
		
	}
	
	function index()
	{
		if ($this->can_view() == FALSE){
			redirect('auth/failed');
		}
		
		$data['can_view'] 	= $this->can_view();
		$data['can_insert'] = $this->can_insert();
		$data['can_update'] = $this->can_update();
		$data['can_delete'] = $this->can_delete();
		
		$this->open();
		$param3 = $this->uri->segment(3);		if ($param3==null)			$param3=0;				$data['param3'] = $param3;
		# config pagination
		$config['base_url'] = base_url().'index.php/penerimaan_kas/index/';
		
		$config['per_page'] = '10';		$config['num_links'] = '5';		$config['uri_segment'] = '3';				$config['full_tag_open'] = '';		$config['full_tag_close'] = '';				$config['num_tag_open'] = '<div id="page-info">';		$config['num_tag_close'] = '</div>';				$config['cur_tag_open'] = '<div id="page-info"><strong>';		$config['cur_tag_close'] = '</strong></div>';				$config['prev_link'] = '<li class="page-left"></li>';		$config['prev_tag_open'] = '';		$config['prev_tag_close'] = '';				$config['next_link'] = '<li class="page-right"></li>';		$config['next_tag_open'] = '';		$config['next_tag_close'] = '';				$config['last_link'] = '<li class="page-far-right"></li>';		$config['last_tag_open'] = '';		$config['last_tag_close'] = '';				$config['first_link'] = '<li class="page-far-left"></li>';		$config['first_tag_open'] = '';		$config['first_tag_close'] = '';				$config['total_rows'] = $this->penerimaan_kas->getItem($config['per_page'], $param3, true);				$this->pagination->initialize($config);	
		# end config pagination
		
		# get data		
		$data['results'] = $this->penerimaan_kas->getItem($config['per_page'], $param3, false);
		
		# load view
		$this->load->view('penerimaan_kas/penerimaan_kas_list', $data);
		
		$this->close();
	}		function insert()	{		if ($this->can_insert() == FALSE){			redirect('auth/failed');		}				$data['can_view'] 	= $this->can_view();			$this->open();		# Data						$akunid			= $this->input->post('akunid');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');				# set rules validation		$this->form_validation->set_rules('akunid', 'akunid', 'required');		/*		*/		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');					# set message validation		$this->form_validation->set_message('required', 'Field %s harus diisi!');		$this->form_validation->set_message('numeric', 'Field %s harus diisi hanya dengan angka!');						if ($this->form_validation->run() == FALSE){			//$data['results']=$this->penerimaan_kas->get_total_tiap_akun();			$data['glid'] = $this->penerimaan_kas->get_glid_ju();			$this->load->view('penerimaan_kas/penerimaan_kas_add',$data);					}else{			# Data					for ($i=0;$i<count($akunid);$i++){				echo $akunid[$i] . '<br/>';			}					}				$this->close();	}		function get_form_data(){				$data['txtBookName'] = $this->input->post('txtBookName');		$data['authorName'] = $this->input->post('authorName');		echo $data['txtBookName'].'<br/><br/>';		$i=0;		foreach ($data['authorName'] as $rows_author){			echo $i . '-' .$rows_author . '<br/>';			$i++;		}	}		function show_akun(){		/*$data['counter']=$this->uri->segment(3);		$data['result'] = $this->penerimaan_kas->get_master_akun();		$this->load->view('penerimaan_kas/list_akun2.php', $data);		*/				$data['counter']=$this->uri->segment(3);		$filter=$this->uri->segment(4);		$this->load->view('penerimaan_kas/list_akun', $data);	}		function getKodeAkun(){		$parent_pecah = $this->input->post('parent_pecah'); 		$get = $this->penerimaan_kas->getKodeAkun($parent_pecah);		 		foreach ($get as $data){			$print = "$data[kode]";			}		echo $print;	}			function show_akun1(){			$data['counter']=$this->uri->segment(3);			$data['result'] = $this->penerimaan_kas->get_master_akun();			$this->load->view('penerimaan_kas/list_akun1', $data);	}		function show_akun4(){		$data['counter']=$this->uri->segment(3);		$data['result'] = $this->penerimaan_kas->get_master_akun4();		$this->load->view('penerimaan_kas/list_akun4', $data);	}		function show_akun5(){		$data['counter']=$this->uri->segment(3);		$filter=$this->uri->segment(4);		$data['tahun'] = $this->penerimaan_kas->getTahun();		$id="";		$data['result'] = $this->penerimaan_kas->get_master_akun2($id);		$this->load->view('penerimaan_kas/list_akun5', $data);	}		function get_kas(){			$akunid=$this->uri->segment(3); 				$data_kas = $this->penerimaan_kas->get_total_tiap_akun($akunid,false);		$data_kas_count = $this->penerimaan_kas->get_total_tiap_akun($akunid,true);				if ($data_kas_count!=0){			$rows=$data_kas->row();			echo $data['data_jml_kas']=$rows->total_kas;		}else{			echo $data['data_jml_kas'] = 0;		}	}		function view_posting_penerimaan_kas(){		$glid			= $this->input->post('glid');		$tanggal			= $this->input->post('tanggal');		$akunid			= $this->input->post('akunid');		$nakun			= $this->input->post('nakun');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');			for ($i=0;$i<count($akunid);$i++){			$data['akunid'][]=$akunid[$i];			$data['nakun'][]=$nakun[$i];			$data['debet'][]=$debet[$i];			$data['kredit'][]=$kredit[$i];		}		$data['glid'] = $glid;		$data['tanggal'] = $tanggal;				$data['jumlah_pemasukan'] = $this->input->post('jumlah_pemasukan');			$data['jumlah_pengeluaran'] = $this->input->post('jumlah_pengeluaran');			$this->load->view('penerimaan_kas/view_posting_penerimaan_kas', $data);		}
	function posting_penerimaan_kas(){		$glid			= $this->input->post('glid');		$tanggal		= $this->input->post('tanggal');		$akunid			= $this->input->post('akunid');		$nakun			= $this->input->post('nakun');		$debet			= $this->input->post('debet');		$kredit			= $this->input->post('kredit');			$jumlah_pemasukan= $this->input->post('jumlah_pemasukan');			$jumlah_pengeluaran= $this->input->post('jumlah_pengeluaran');			$glid_penerimaan_kas=$this->penerimaan_kas->get_glid_ju();				$data_ju['glid']=$glid_penerimaan_kas;		$data_ju['tanggal']=$tanggal;		$data_ju['jumlah']=$jumlah_pemasukan;		$data_ju['status_posting']='0';				$data_j['GLID']=$glid;		$data_j['GLID_PARENT']=$glid_penerimaan_kas;		$data_j['TANGGAL']=$tanggal;				for ($i=0;$i<count($akunid);$i++){			$data_dju['glid']=$glid;			$data_dju['cdate']=$tanggal;			$data_dju['akunid']=$akunid[$i];			$data_dju['debet']=$debet[$i];			$data_dju['kredit']=$kredit[$i];						$data_dj['GLID']=$glid;			$data_dj['AKUNID']=$akunid[$i];			$data_dj['DEBET']=$debet[$i];			$data_dj['KREDIT']=$kredit[$i];			/*$this->penerimaan_kas->insert_detail_j($data_dj);*/			$this->penerimaan_kas->insert_detail($data_dju);//detail_penerimaan_kas		}		$this->penerimaan_kas->insert($data_ju);		/*$this->penerimaan_kas->insert_j($data_j);*/				redirect('penerimaan_kas');	}		function detail_penerimaan_kas_list(){		$glid1=$this->uri->segment(3);		$glid2=$this->uri->segment(4);		$glid3=$this->uri->segment(5);		$glid=$glid1.'/'.$glid2.'/'.$glid3;		$data['results'] = $this->penerimaan_kas->get_detail_penerimaan_kas_list($glid);		$this->load->view('penerimaan_kas/view_detail_penerimaan_kas_list', $data);	}		function detail_penerimaan_kas(){		$glid1=$this->uri->segment(3);		$glid2=$this->uri->segment(4);		$glid3=$this->uri->segment(5);		$glid=$glid1.'/'.$glid2.'/'.$glid3;		$data['results'] = $this->penerimaan_kas->get_detail_penerimaan_kas($glid);		$this->load->view('penerimaan_kas/view_detail_penerimaan_kas', $data);	}		function list_posting(){		if ($this->can_view() == FALSE){			redirect('auth/failed');		}		$data['can_view'] 	= $this->can_view();		$data['can_insert'] = $this->can_insert();		$data['can_update'] = $this->can_update();		$data['can_delete'] = $this->can_delete();		$this->open();		$config['base_url'] = base_url().'index.php/penerimaan_kas/list_posting/';		$config['total_rows'] = 		//$this->db->count_all('penerimaan_kas');		sizeof($this->db->select('penerimaan_kas.glid')             ->from('penerimaan_kas')			->where('status_posting','0')            ->get()			->result()); 		$config['per_page'] = '10';		$config['num_links'] = '5';		$config['uri_segment'] = '3';				$config['full_tag_open'] = '';		$config['full_tag_close'] = '';		$config['num_tag_open'] = '<div id="page-info">';		$config['num_tag_close'] = '</div>';		$config['cur_tag_open'] = '<div id="page-info"><strong>';		$config['cur_tag_close'] = '</strong></div>';				$config['prev_link'] = '<li class="page-left"></li>';		$config['prev_tag_open'] = '';		$config['prev_tag_close'] = '';		$config['next_link'] = '<li class="page-right"></li>';		$config['next_tag_open'] = '';		$config['next_tag_close'] = '';				$config['last_link'] = '<li class="page-far-right"></li>';		$config['last_tag_open'] = '';		$config['last_tag_close'] = '';				$config['first_link'] = '<li class="page-far-left"></li>';		$config['first_tag_open'] = '';		$config['first_tag_close'] = '';				$this->pagination->initialize($config);			$data['results'] = $this->penerimaan_kas->get_item_list_unposting($config['per_page'], $this->uri->segment(3));				$this->load->view('penerimaan_kas/penerimaan_kas_list_unposting', $data);		$this->close();	}				function posting(){		$glid			= $this->input->post('glid');						for ($i=0;$i<count($glid);$i++){						$rows_ju = $this->penerimaan_kas->get_item_penerimaan_kas($glid[$i]);						foreach ($rows_ju->result() as $rows){				$glid_jurnal = $this->penerimaan_kas->get_glid_jurnal();				$data_j['GLID']=$glid_jurnal;				$data_j['GLID_PARENT']=$rows->glid;				$data_j['TANGGAL']=$rows->tanggal;				$this->penerimaan_kas->insert_j($data_j);										$rows_dju = $this->penerimaan_kas->get_detail_item_penerimaan_kas($rows->glid);					foreach ($rows_dju->result() as $rows_dju){						$data_dj['GLID']=$glid_jurnal;						$data_dj['AKUNID']=$rows_dju->akunid;						$data_dj['DEBET']=$rows_dju->debet;						$data_dj['KREDIT']=$rows_dju->kredit;						$this->penerimaan_kas->insert_detail_j($data_dj);					}												}						$data['status_posting']='1';			$this->penerimaan_kas->update_posting_penerimaan_kas($glid[$i],$data);					}		$this->list_posting();			}		function getParent_1(){		$kirim = $this->input->post('kirim');		$pieces = explode("#", $kirim);		$tahun = $pieces[0];		$counter = $pieces[1];		$result = $this->penerimaan_kas->get_master_akun2($tahun);				$i=0;				echo 				"				<thead>					<tr>																<th class='table-header-repeat line-left minwidth-0' width='10px'><a href=''>Nomor</a></th> 						<!--<th class='table-header-repeat line-left minwidth-1'><a href=''>Parent</a></th>	-->						<th class='table-header-repeat line-left minwidth-0'><a href=''>Kode</a></th>		 												<th class='table-header-repeat line-left minwidth-1'><a href=''>Uraian</a></th>  						<th class='table-header-repeat line-left minwidth-1'><a href=''>Nilai</a></th>								<th class='table-header-repeat line-left minwidth-1'><a href=''>Realisasi</a></th>							<th class='table-header-repeat line-left minwidth-1'><a href=''>Sisa</a></th>												</tr>				</thead>				<tbody id='items'>				</tbody>				";				foreach($result->result() as $row) 				{				$i=$i+1;				 								$hasil1=strlen(str_replace(" ", "", $row->kode));							 				if(((preg_match("/[.]/",$row->kode ))&&($hasil1 == 8))&&(preg_match("/[0-9]/",$row->kode )))				{					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";										echo "<td>&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "<b>".$row->kode."</b>"; 					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";										echo "</tr>"; 				}				elseif((preg_match("/[.]/",$row->kode ))&&(preg_match("/[0-9]/",$row->kode )))				{					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";					echo "<td><b>".$row->kode."</b>";  					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";					echo "</tr>"; 				}				elseif(($hasil1 == 4)&&(preg_match("/[0-9]/",$row->kode )))				{					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";					echo "<td>&nbsp;&nbsp;";					echo "<b>".$row->kode."</b>"; 					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";					 					echo "</tr>"; 				}								elseif(($hasil1 == 3)&&(preg_match("/[0-9]/",$row->kode )))				{					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";					echo "<td>&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "<b>".$row->kode."</b>"; 					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";					 					echo "</tr>"; 				}				elseif(preg_match("/[a-zA-Z]/",$row->kode ))				{ 					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";					echo "<td>&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;";					echo "<b>".$row->kode."</b>"; 					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";					 					echo "</tr>"; 				}				else if(preg_match("/[0-9]/",$row->kode ))				{					echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";					echo "<td>&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "&nbsp;&nbsp;";					echo "<b>".$row->kode."</b>"; 					echo "&nbsp;</td>";					echo "<td><b>".$row->uraian."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->jumlah)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->realisasi2)."</b></td>";					echo "<td style='text-align:right'><b>".convert_rupiah_non_rp($row->sisa2)."</b></td>";					 					echo "</tr>"; 					 				}								elseif((preg_match("/[>]/",$row->uraian )) or (preg_match("/[>>]/",$row->uraian )))				{											echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";						//echo "<td><b>".$row->kode."</b></td>";						echo "<td>&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;</b>";						echo "&nbsp;</td>";					echo "<td><i><u>".$row->uraian."</u></i></td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->jumlah)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->realisasi2)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->sisa2)."</td>";						 						echo "</tr>"; 				}				elseif(preg_match("/[-]/",$row->uraian ))				{						echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";											//echo "<td><b>".$row->kode."</b></td>";						echo "<td>&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "&nbsp;&nbsp;";						echo "<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;</b></td>";						 //echo "//<td>";						 //\'$row->parent\',\'$row->kode\',\'$row->uraian\',\'$row->jumlah\',\'$row->realisasi2\',\'$row->sisa2\',\'\'					$print = "<td><a href='javascript:set_barang3(\"$row->parent\",\"$row->kode\",\"$row->uraian\",\"$row->jumlah\",\"$row->realisasi2\",\"$row->sisa2\",\"".$counter."\")'>".$row->uraian."</a></td>";					echo $print;					//echo "</a></td>";					//echo "\"with quotes\" or without quotes\'asda";					//echo "asdasdasd";					//echo $row->uraian."</a></td>";					//echo "<td>".$row->uraian."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->jumlah)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->realisasi2)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->sisa2)."</td>";						 echo "</tr>";						 				}				else				{						echo "<tr>";					echo "<td>".$i."</td>";					//echo "<td>".$row->parent."</td>";						echo "<td><b>".$row->kode."</b></td>";						echo "<td>kosong</td>";						echo "<td>&nbsp;</td>";						echo "<td>&nbsp;</td>";						echo "<td>&nbsp;</td>";						echo "<td>&nbsp;</td>";						echo "<td>&nbsp;</td>";					echo "<td>".$row->uraian."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->jumlah)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->realisasi2)."</td>";					echo "<td style='text-align:right'>".convert_rupiah_non_rp($row->sisa2)."</td>";						echo "</tr>";				}				 }  		echo $data1;	}	
}